<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>修改管理员</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath }/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 日期插件样式 -->
    <link href="${pageContext.request.contextPath }/css/foundation-datepicker.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js?v=3.3.6"></script>
    
    <!-- 自定义js -->
    <script src="${pageContext.request.contextPath }/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="${pageContext.request.contextPath }/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/plugins/layer/layer.min.js"></script>
    <!-- 日期插件js-->
    <script src="${pageContext.request.contextPath }/js/foundation-datepicker.js" type="text/javascript"></script>
    
    
    <script type="text/javascript">
    
 	// 手机号码验证  
    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "请正确填写您的手机号码");
 
    $().ready(function () {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#update_admin").validate({
            rules: {
            	realname: {//姓名
                    required: true,
    				maxlength: 20
                },
                roleid: {//角色
                    required: true,
                },
                username: {//登录帐号
                    required: true,
                    remote: {
    					url: "${pageContext.request.contextPath }/admin/admin/isExists",
    					cache: false,
    				    data:{
    				       username:function(){return $("#username").val();},
    				       id:function(){return $("#id").val();}
    				    },
    				maxlength: 20
    				}
                },
                telphone: {//电话
                    required: true,
                    isMobile:true,
                    remote: {
    					url: "${pageContext.request.contextPath }/admin/admin/isTelphone",
    					cache: false,
    				    data:{
    				    	telphone:function(){return $("#telphone").val();},
    				       id:function(){return $("#id").val();}
    				    },
                    },
    				minlength: 11
                },
            },
            messages: {
            	realname:{
            		required:icon + "请填写姓名",
            		maxlength:icon + "最大长度为20"
            	},
            	roleid:icon + "请选择角色",
            	username: {
            		required:icon + "请输入登录帐号",
            		remote:icon + "登录帐号已存在",
            		maxlength:icon + "最大长度为20"
            		},
            	telphone:{
            		required:icon + "请填写电话",
            		isMobile:icon + "请输入正确格式",
            		remote:icon + "手机号已存在",
            		minlength:icon + "请输入11位"
            	},
                
            },
    		submitHandler: function(form) {
    			updateAdmin();
    		}
        });
    });
	//修改
	function updateAdmin(){	
		var pwd = $("#password").val();
		if(pwd != null && pwd != ""){
			if(pwd.length < 6 || pwd.length > 15){
				alert("密码长度为6－15位");
				$("#password").val("");
				$("#password").focus();
				return;
			}
		}
		$.ajax({
    		url:"${pageContext.request.contextPath }/admin/admin/updateAdmin",
    		data:$("#update_admin").serialize(),
    		type:"post",
    		success:function(data){
    			if(data.code == 0){
					layer.msg(data.message,{icon:1});
					setTimeout('cancel()',1000);
    			}else {
					layer.msg(data.message,{icon:0});
    			}
    		}
    	});
	}
  	//取消
    function cancel(){
   	 	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
    }
    </script>
    <script type="text/javascript">
    //如果是超级管理员则隐藏公司列表
    $().ready(function (){
      var index=$("#roleList option:selected").text();
  	  if(index=='超级管理员'){
  		  $("#companyList").hide();
  	  }
    });
      function isShowCompany(){
    	  var index=$("#roleList option:selected").text();
    	  if(index=='超级管理员'){
    		  $("#companyList").hide();
    	  }else{
    		  $("#companyList").show();
    	  }
      }
    </script>
	<style>
		input,select{
			 width:168px;
			 height:25px;
			 border:1px solid #ccc;
			 margin-left:24px;
		}
		.label-text{
			width:80px;
			text-align:right;
		}
		
		.form-item{
			display:flex;
		}
		.label-text{
		   height: 34px;
		   line-height: 34px;
		   font-weight: normal;
		}
		.addInput{ 
			background-color: #ffffff;
		    background-image: none;
		    border: 1px solid #e5e6e7;
		    border-radius: 1px;
		    color: inherit;
		    display: block;
		    font-size: 14px;
		    padding: 6px 12px;
		    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
		    height: 34px;
		   line-height: 34px;
		   flex: 1;
		}
		.saveBtn{
			 display: block;
		    margin: 15px auto;
		    width: 120px;
		}
		.demo-3{ 
			background-color: #ffffff;
		    background-image: none;
		    border: 1px solid #e5e6e7;
		    border-radius: 1px;
		    color: inherit;
		    display: block;
		    font-size: 14px;
		    padding: 6px 12px;
		    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
		    height: 34px;
		   line-height: 34px;
		   flex: 1;
		}
	</style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-6">
                <div class="social-feed-box">
                    <div class="social-footer">
						<form name = "form1" id = "update_admin">
							<input type = "hidden" id = "id" name = "id" value = "${a.id }"/>
							<div class="form-item">
								<label class="label-text">姓名：</label>
								<input type = "text" name = "realname" class="addInput" value = "${a.realname }"  placeholder="输入姓名，不超过20字" maxlength="20" ><br/><br/>
							</div>
							<div class="form-item">
								<label class="label-text">登录帐号：</label> 
								<input type = "text" name = "username" class="addInput" id = "username" value = "${a.username }"  disabled="disabled"/><br/><br/>
							</div>
							<div class="form-item">
								<label class="label-text">登录密码：</label>
								<input type = "password" name = "password" class="addInput" id = "password"  placeholder="如为空，则不修改" /><br/><br/>
							</div>
							<div class="form-item">
								<label class="label-text">电话：</label>
								<input type = "text" name = "telphone" class="addInput" id = "telphone" value = "${a.telphone }" placeholder="输入手机号" maxlength="11"/><br/><br/>
							</div>
							<!-- <div class="form-item">
								<label class="label-text">数量：</label>
								<input type = "text" name = "counts" class="addInput" id = "counts" value = "${a.counts }"/><br/><br/>
							</div> -->
							<div class="form-item">
								<label class="label-text">到期时间：</label>
								<input class="demo-3" type = "text" name = "endtime" id="endtime" value = "${a.enddate }"/><br/><br/>
							</div>
							<button type = "submit" class="btn btn-primary saveBtn">确定</button>
					    </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>

<script type="text/javascript">
	function formatDate(date, format) {
		if (!date) return;
		if (!format) format = "yyyy-MM-dd";
		switch (typeof date) {
			case "string":
				date = new Date(date.replace(/-/, "/"));
				break;
			case "number":
				date = new Date(date);
				break;
		}
		if (!date instanceof Date) return;
		var dict = {
			"yyyy": date.getFullYear(),
			"M": date.getMonth() + 1,
			"d": date.getDate(),
			"H": date.getHours(),
			"m": date.getMinutes(),
			"s": date.getSeconds(),
			"MM": ("" + (date.getMonth() + 101)).substr(1),
			"dd": ("" + (date.getDate() + 99)).substr(1),
			"HH": ("" + (date.getHours() + 110)).substr(1),
			"mm": ("" + (date.getMinutes() + 100)).substr(1),
			"ss": ("" + (date.getSeconds() + 100)).substr(1)
		};
		return format.replace(/(yyyy|MM?|dd?|HH?|ss?|mm?)/g, function() {
			return dict[arguments[0]];
		});
	}
	var webVal = $("#endtime").val();
	var c = formatDate(webVal, "yyyy-MM-dd HH:mm:ss");
	$("#endtime").val(c);
</script>
<script>
	var nowTemp = new Date();
	var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), nowTemp.getHours(), nowTemp.getMinutes(), 0, 0);
	$('.demo-3').fdatepicker({
		format: 'yyyy-mm-dd hh:ii',
		pickTime: true,
		onRender: function (date) {
			return date.valueOf() < now.valueOf() ? 'disabled' : '';
		}
	});
	</script>
</html>
